<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Simulations for Statistical and Thermal Physics</title>

<link href="../default.css" type="text/css" rel="stylesheet">

</head>

<body>
<h3 style="text-align:center;">Monte Carlo estimation</h3>

<p class="header_title">Introduction</p>

<p>The program estimates the area under the curve given by</p>
<p class="center">
<img src="fx.jpg" alt="" align="middle" >
</p>
<p>with x between 0 to 1 using the Monte Carlo hit and miss method.</p>

<center>
<applet
 code="org.opensourcephysics.davidson.applets.ApplicationApplet.class"
 archive="./stp.jar" codebase="../" align="top" height="40"
 hspace="0" vspace="0" width="150"> <param name="target"
 value="org.opensourcephysics.stp.estimation.MonteCarloEstimationApp"> <param name="title"
 value="Applet"> <param name="singleapp" value="true">
</applet>
</center>

<p class="header_title">Algorithm</p>

<p class="center">
<img src="domain.jpg" alt="" align="middle" >
</p>

<p>Imagine a
rectangle of height
h, width
b - a, and area A = h(b - a) such that the function f(x) is within the
boundaries of the rectangle. Generate
n pairs of random numbers x<sub>i</sub> and
y<sub>i</sub> with a &#8804; x<sub>i</sub> &#8804; b and 0 &#8804; y<sub>i</sub> &#8804; h. The fraction of points x<sub>i</sub>, y<sub>i</sub> that satisfy the condition y<sub>i</sub>
&#8804; f(x<sub>i</sub>) is an estimate of the ratio of the integral of f(x) to the
area of the rectangle. Hence, the estimate
F<sub>n</sub> in the <i>hit or miss</i> method is given by</p>
<p class="center">
<img src="estimate.jpg" alt="" align="middle" >
</p>
<p>where n<sub>s</sub> is the number of points below the curve and
n is the total number of points.</p>

<p class="header_title">Problems</p>

<ol>

<li>Calculate the exact answer by doing the following integral analytically:
<p class="center">
<img src="integral.jpg" alt="" align="middle" >
</p>
</li>

<li>Determine the error (the magnitude of the deviation from the exact answer) for Monte Carlo runs of n = 10<sup>4</sup> and 10<sup>5</sup>, 10<sup>6</sup>, and 10<sup>7</sup>. 
Plot the log of the error versus log n. Does the error decrease with increasing n on the average?</li>

<li>Estimate the integral using n = 100 points. Repeat for a total of 10 trials using different random number seeds each time.  The easiest way to do so is to press the <tt>Reset</tt> button and then press the <tt>Calculate</tt> button. The default is for the program to choose a new seed each time based on the time.
Is the magnitude of the variation of your values of the same order as the error between the average value and the exact 
value? For a large number of trials, the error is estimated from the standard error of the mean, which approximately equals the 
standard deviation divided by the square root of the number of trials.</li>

</ol>

<p class="header_title">References</p>

<ul>

<li>Harvey Gould, Jan Tobochnik, and Wolfgang Christian, <i>Introduction to Computer Simulation Methods,</i> Addison-Wesley (2006), pp. 421&#8211;424.</li>
</ul>

<p class="header_title">Java Classes</p>

<ul>

<li>MonteCarloEstimationApp</li>
</ul>

<p class = "small">Updated 27 February 2007.</p>
</body>

</html>
